import { h } from "vue";
import type { Component } from "vue";
import type { MenuOption } from "naive-ui";
import { IconProps, NIcon } from "naive-ui";

/**
 * 渲染图标
 * @param icon - Vue 组件
 * @returns VNode 或 undefined
 */
// export function renderIcon(icon: Component) {
//   return () => h(icon);
// }

/**
 * 渲染菜单标签
 * @param option - 菜单选项
 * @returns 标签文本
 */
export function renderMenuLabel(option: MenuOption) {
  return option.label as string;
}

/**
 * 渲染菜单图标
 * @param icon - 菜单图标组件
 * @returns VNode 或 undefined
 */
export function renderMenuIcon(icon: Component) {
  return renderIcon(icon);
}

/**
 * render 图标
 * */
export function renderIcon(icon, option: IconProps = { size: 16 }) {
  return () => h(NIcon, option, { default: () => h(icon) });
}
